package des.wangku.operate.standard.utls;

import java.net.InetAddress;
/**
 * 得到本地的一些信息
 * 
 * @author Sunjian
 * @version 1.0
 * @since jdk1.8
 */
public class UtilsInetAddress {
	/**
	 * 得到本机名称 别名
	 * @return String
	 */
	public static final String getHostName() {
        try
        {
            InetAddress addr = InetAddress.getLocalHost();
            if(addr==null)return null;
            return addr.getHostName();
        }
        catch (Exception ex)
        {
            System.out.println("Hostname can not be resolved");
            return null;
        }
	}
	/**
	 * 得到本机名称 全名
	 * @return String
	 */
	public static final String getCanonicalHostName() {
        try
        {
            InetAddress addr = InetAddress.getLocalHost();
            if(addr==null)return null;
            return addr.getCanonicalHostName();
        }
        catch (Exception ex)
        {
            System.out.println("Hostname can not be resolved");
            return null;
        }
	}
	/**
	 * 得到本机ip地址全部
	 * @return String[]
	 */
	public static final String[] getgetHostAddress() {
		String[] arr= {};
        try
        {
            InetAddress addr = InetAddress.getLocalHost();
            if(addr==null)return arr;
            InetAddress[] address = InetAddress.getAllByName(addr.getHostName());
            int len=address.length;
            if(len==0)return arr;
            String[] result=new String[len];
            for(int i=0;i<address.length;i++){
              String strAdress = address[i].getHostAddress();
              result[i]=strAdress;
            }
            return result;
        }
        catch (Exception ex)
        {
            System.out.println("Hostname can not be resolved");
            return arr;
        }
	}
}
